package com.lyn.hy;

import com.lyn.domain.TblDataHyydflb;
import org.jfaster.mango.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@DB(table="TBL_DATA_HYYDFLB")
@Sharding(tableShardingStrategy = HyydflbShardingStrategy.class)
public interface HyydflbDao {
    // 插入数据
    @SQL("insert into #table(nian, yue, tjm, dwdm, pri_ydl, pri_ydl_lj) values(:nian, :yue, :tjm, :dwdm, :priYdl, :priYdlLj)")
    public int insert(@TableShardingBy("nian") TblDataHyydflb hy);

    //根据主键更新单条记录
    @SQL("update #table set pri_ydl=:priYdl, pri_ydl_lj=:priYdlLj" +
            " where guid=:guid")
    public int updateById(@TableShardingBy("nian") TblDataHyydflb hy);

    @SQL("update #table set #if(:priYdl!=null) pri_ydl=:priYdl, " +
            " #else pri_ydl=null, #end " +
            " #if(:priYdlLj != null) pri_ydl_lj=:priYdlLj " +
            " #else pri_ydl_lj=null #end" +
            " where nian=:nian and yue=:yue and tjm=:tjm and dwdm=:dwdm")
    public int customUpdate(@TableShardingBy("nian") TblDataHyydflb hy);

    //根据主键更新单条记录
    @SQL("select * from #table where guid=:guid")
    public TblDataHyydflb getById(@TableShardingBy("nian") TblDataHyydflb hy);

    //自定义条件查询若干条记录
    @SQL("select * from #table " +
            "where nian=:nian and yue=:yue and dwdm=:dwdm order by tjm")
    public List<TblDataHyydflb> customSelect(@TableShardingBy("nian") TblDataHyydflb hy);

    @SQL("select * from #table where nian=:nian and yue=:yue and dwdm=:dwdm and tjm in (:tjm)")
    public List<TblDataHyydflb> customSelectIn(@TableShardingBy @Rename("nian") BigDecimal nian, @Rename("yue") BigDecimal yue,
                                               @Rename("dwdm") String dwdm, @Rename("tjm") List<String> tjm);

    @SQL("select * from #table where nian=:nian and yue=:yue and dwdm=:dwdm and tjm like :tjm")
    public List<TblDataHyydflb> customSelectLike(@TableShardingBy @Rename("nian") BigDecimal nian, @Rename("yue") BigDecimal yue,
           @Rename("dwdm") String dwdm, @Rename("tjm") String tjm);

    @SQL("select a.*, b.deptname DEPTNAME from #table a inner join dept b on a.dwdm=b.guid where nian=:nian and yue=:yue and dwdm=:dwdm")
    public List<HyVo> customSelectJoin(@TableShardingBy @Rename("nian") BigDecimal nian, @Rename("yue") BigDecimal yue,
                                                 @Rename("dwdm") String dwdm);

}
